using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Microsoft.DirectX.DirectDraw;
using System.Windows.Forms;
using TowerDefense_Dx.Core;
using TowerDefense_Dx.GameLogic;
using TowerDefense_Dx.Button;

namespace TowerDefense_Dx.Screen
{
    class MainGameScreen:DxScreen
    {
        private int _level;
        private TowerButton _buttion1;

        DxImage _gameBolder;

        private WaveManager waves;
        private Player player;
        private Level level;

        public MainGameScreen(DxInitGraphics graphics, Size size, Point position,DxMouse mouse,int level):
        base(graphics,size,position,mouse)
        {
            _graphics = graphics;
            _screenSize = size;
            _position = position;
            _mouse = mouse;
            _level = level;
            Restore();
        }
        public override void Init()        {

            _gameBolder = new DxImage("Sprite/gameBolder.png",_graphics.GraphicsDevice);
           
            _buttion1 = new TowerButton("Sprite/sprite.png", _graphics.GraphicsDevice, 32, 32, new PointF(18*32, 6*32));
            //waves = new WaveManager(_graphics,"Sprite/robot.png", 5);
            player = new Player(_graphics);
            level = new Level(_graphics,"Map/map1.txt","Map/map.png",32,32);
        }
        public override void Update(double deltaTime)
        {
            //waves.Update(deltaTime, player);     
            level.Update(deltaTime, player);
            player.Update(deltaTime, level.Waves.Enemies);
            _buttion1.Update(_mouse.GetMouseState(), _graphics, player,level.ColisionMap);
        }
        public override void Draw(double deltaTime)
        {
            _gameBolder.DrawFast(0, 0, _screenSurface, DrawFastFlags.Wait);
            
            
            level.Draw(_screenSurface, new Point(3, 96));
            //waves.Draw(_screenSurface);
            player.DrawTower(_screenSurface);            
            _buttion1.DrawFast(_screenSurface, Microsoft.DirectX.DirectDraw.DrawFastFlags.Wait);
            _buttion1.DrawSprite(_screenSurface);
            //if (level.Waves.CurrentWave.EnemyList.Count > 0 && player.TowerList.Count > 0)
            //{
            //    _screenSurface.DrawText(50, 20, "enemy:" + level.Waves.CurrentWave.EnemyList[0].Center.ToString(), false);
            //    _screenSurface.DrawText(100, 20, "target:" + player.TowerList[0]._targetList[0].Center, false);
            //}
            _screenSurface.DrawText(300, 50, "Wave: " + level.Waves.CurrentWave.WaveNumber, false);
            _screenSurface.DrawText(170, 50, "Time: " + level.Waves.WaveTime.ToString(), false);
            _screenSurface.DrawText(50, 50,"Money: " + player.Money.ToString(), false);
            _screenSurface.DrawText(500, 50,"Lives: " + player.Lives.ToString(), false);
            _graphics.BackBuffer.DrawFast(0,0, _screenSurface, DrawFastFlags.Wait);
        }
    }
}
